﻿using System;
using System.Collections.Generic;
using System.Linq;


namespace WP7.Extensions.Extensions
{
    public static class UriExtensions
    {
        /// <summary>
        /// Gets the parameters in uri
        /// </summary>
        /// <param name="self">Uri to get parameters from</param>
        /// <returns>Parameters from Uri</returns>
        public static Dictionary<string, string> Parameters(this Uri self)
        {
            if (self.IsNull())
                throw new ArgumentException("Uri can't be null.");

            return String.IsNullOrEmpty(self.Query)
              ? new Dictionary<string, string>()
              : self.Query.Substring(1).Split('&').ToDictionary(
                  p => p.Split('=')[0],
                  p => p.Split('=')[1]
              );
        }
    }
}
